Histogram Model: Color Feature


Sergei Papulin (papulin.edu@gmail.com)

Contents

Creating virtual environment

This is an optional step. You can skip it and install packages to your current environment.

python -m venv .venv/histtest
source .venv/histtest/bin/activate
pip install \
    numpy==1.19.5 \
    plotly==5.5.0 \
    jupyter==1.0.0 \
    pillow==5.4.1 \
    scikit-image==0.14.2 \
    himpy=0.0.1

Load packages

Generating Images

Defining Color Elements

Low-Level Elements

Stucture of color elements:

[
    {
        "id": id,
        "h": [min, max],
        "s": [min, max],
        "b": [min, max]
    }, ...
]

Parameters:

High-Level Elements

$$E^G=\left\{E\vert E\subseteq U\right\}$$

Creating Histogram

Normalized histogram of an image can be written as

$$H(d)=\left( h(e_1), \cdots, h(e_n) \mid h(x)=h(x \mid d), 0 \leq h(x) \leq 1, \sum_{x\in U}h(x) = 1 \right).$$
Table 1. Basic notations [1]
Symbol Definition
$$U$$ Universal set (all possible elements that make up data instances)
$$x$$ Element of the universal set, $x \in U$
$$d$$ Data instance
$$N(d)$$ The total number of elements in $d$
$$X$$ High-level element that is a subset of the universal set, $X\subseteq U$
$$H(d)$$ Histogram of a data instance
$$h(x \mid d)$$ Value that corresponds to element $x$ of histogram $H(d)$
$$H(X \mid d)$$ Histogram of high-level element $X$ given a data instance $d$
$$h(x \mid X, d)$$ Value that corresponds to element $x$ of histogram $H(X \mid d)$

Total number of elements in the image:

Non-zero elements of the histogram:

Sum of all histogram element values:

Get a value of the first histogram element:

Get a value of the e1 element:

or

Querying

If $U$ is a finite set, then the set of all subsets of $U$, or the $\sigma$-algebra over $U$, is defined as follows

$$ E^G=\left\{X\vert X \subseteq U\right\}. $$

Each element $X$ in $E^G$ can be mapped to its histogram $H(X \mid d)$. So, the whole set of histograms for $E^G$ given a data instance $d$ is

$${H}^{G}(d) = \left \lbrace H(X|d) \mid X \in E^G \right \rbrace.$$

And a single mapping $X$ to $H(X \mid x)$ can be defined as follows

$$ H(X \mid d) = \left(h(e_1),\cdots,h(e_n) \mid h(x)=\left\{\begin{array}{l}h(x \mid d)\;\text{if}\;x \in X,\\0\;\text{otherwise}\end{array}\right. \right) \in H^G(d).$$

Operations on Histogram Elements

The histogram algebraic system can be denoted as follows

$$\mathcal{H} = \left\langle H^G,\cap,\cup,\land,\dot\lor,\lor,\dot\backslash,\setminus, -, \mathbf{0},\mathbf{1}\right\rangle,$$

where constants are defined as

$$\mathbf{0}=H^0=\left( h(e_1), \cdots, h(e_n) \mid h(x) = 0, x \in U \right)$$$$\mathbf{1}=H^1=H(d)=\left( h(e_1), \cdots, h(e_n) \mid h(x) = h(x \mid d), x \in U, \sum_{x\in U}h(x)=1 \right)$$

Set Operations

UNION

$$H_1 \cup H_2 =\left(h(e_1),\cdots,h(e_n) \mid h(x)=\max(h(x \mid X_1,d), h(x \mid X_2, d)) \right)$$

Show the histogram of E_union given the image:

INTERSECTION

$$ H_1 \cap H_2 =\left(h(e_1),\cdots,h(e_n) \mid h(x)=\min(h(x \mid X_1, d), h(x \mid X_2, d)) \right)$$

Case 1

Show the histogram of E_intercept given the image:

Case 2

SUBSTRACTION or EXCEPTION

$$ H_1 \setminus H_2 =\left(h(e_1),\cdots,h(e_n) \mid h(x)=\left\{\begin{array}{l}h(x \mid X_1, d)\;\text{if}\;h(x \mid X_2, d)=0,\\0\;\text{otherwise}\end{array}\right. \right),$$

where $H_i = H(X_i \mid d)$ and $X_i \in E^G$.

Case 1

Show the histogram of E_sub given the image:

Case 2

Logical Operations

AND

$$H_1\land H_2=\left\{\begin{array}{l}H_1\;\text{if}\;{}^\Sigma H_1 < {}^\Sigma H_2,\\H_2\;\text{otherwise}\end{array}\right.,$$

where

$$ {}^\Sigma H_i(d) = \sum_{x\in X_i}h(x \mid d)$$

Show the histogram of E_and given the image:

OR

$$ H_1 \lor H_2 =\left(H(e_1),\cdots,H(e_n) \mid h(x)=\max(h(x \mid X_1, d), h(x \mid X_2, d)) \right)$$

Show the histogram of E_or given the image:

XOR

$$ H_1\dot\lor H_2=\left\{\begin{array}{l}H_1\;\text{if}\;{}^\Sigma H_1 > {}^\Sigma H_2,\\H_2\;\text{otherwise}\end{array}\right..$$

Show the histogram of E_xor given the image:

XSUBSTRACTION

$$ H_1\dot\backslash H_2=\left\{\begin{array}{l}0\;\text{if}\;{}^\Sigma H_2 > 0,\\H_1\;\text{otherwise}\end{array}\right.$$

Case 1

Show the histogram of E_xsub given the image:

Case 2

Show the histogram of E_xsub given the image:

Data Analysis

Set a query:

Compute a histogram of the query given the image:

Image Retrieval

Expression as query

Image sample as query

References